package com.qf.advice;/*
 *徐韬
 *2021/10/19
 *8:26
 */

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice2 {
    @Pointcut("execution(* com.qf.service.impl.AddressServiceimpl.add(..))")
    public void pc(){}
    @Pointcut("execution(* com.qf.service.impl.AddressServiceimpl.modfig(..))")
    public void pc2(){}
    @Pointcut("execution(* com.qf.service.impl.AddressServiceimpl.remove(..))")
    public void pc3(){}
    @Pointcut("execution(* com.qf.service.impl.AddressServiceimpl.select(..))")
    public void pc4(){}
    @Pointcut("execution(* com.qf.service.impl.AddressServiceimpl.selectAll(..))")
    public void pc5(){}
    @Before("pc()")
    public void before(){
        System.out.println("增强日志");
    }
    @AfterReturning(value = "pc2()",returning = "result")
    public void afterReturn(int result){
        System.out.println("增强后得结果为："+result);
    }
    @Around("pc3()")
    public void around(ProceedingJoinPoint proceedingJoinPoint)throws Throwable{
        try {
            System.out.println("开启事务");
            proceedingJoinPoint.proceed();
            System.out.println("提交事务");
        } catch (Throwable throwable) {
            System.out.println("回滚事务");
            throwable.printStackTrace();
        }


    }
    @After("pc4()")
    public void after(){
        System.out.println("最终增强执行了");
    }
     @AfterThrowing(value = "pc5()",throwing = "e")
    public void afterThrowing(Exception e){
         System.out.println("异常增强执行了"+e.getMessage());
    }
}
